#include <algorithm>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
class Solution {
public:
    int minDistance(string word1, string word2) {
        vector<vector<int>>dp(word1.size()+1,vector<int>(word2.size()+1));
        int l1=word1.size();
        int l2=word2.size();
        if(l1*l2==0)return l1+l2;
        for(int i=0;i<=l1;i++)
            dp[i][0]=i;
        for(int j=0;j<=l2;j++)
            dp[0][j]=j;
        for(int i=1;i<=l1;i++)
        {
            for(int j=1;j<=l2;j++)
            {
                //skip情况
                if(word1[i-1]==word2[j-1])dp[i][j]=dp[i-1][j-1];//dp从1开始，对应的word为-1   
                //replace delete insert 三者找最小的可能
                else dp[i][j]=min(dp[i-1][j-1]+1,min(dp[i-1][j]+1,dp[i][j-1]+1));
            }
        }
        return dp[l1][l2];
    }
};